package com.tianma315.admin.produce.controller;


import java.util.Arrays;
import java.util.Calendar;
import java.util.List;

import com.tianma315.admin.common.base.BaseController;
import com.tianma315.admin.common.utils.Result;
import com.tianma315.admin.produce.VO.ScDisinfectVO;
import com.tianma315.admin.produce.domain.ScBatchingDO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tianma315.admin.produce.domain.ScDisinfectDO;
import com.tianma315.admin.produce.service.ScDisinfectService;

/**
 * 
 * <pre>
 * 杀菌(生产)
 * </pre>
 * <small> 2019-05-30 09:53:18 | Aron</small>
 */
@Controller
@RequestMapping("/produce/scDisinfect")
public class ScDisinfectController extends BaseController{
	@Autowired
	private ScDisinfectService scDisinfectService;
	
	@GetMapping()
//	@RequiresPermissions("produce:scDisinfect:scDisinfect")
	String ScDisinfect(){
	    return "produce/scDisinfect/scDisinfect";
	}

	@GetMapping("/{produceTaskId}")
	String ScDisinfect(@PathVariable("produceTaskId") Integer produceTaskId,Model model){
		List<ScDisinfectDO> list = scDisinfectService.getScDisinfectDO(produceTaskId);
		Boolean flag = false;
		if (list==null || list.isEmpty()){
			flag = true;
		}
		model.addAttribute("produceTaskId",produceTaskId);
		model.addAttribute("flag",flag);
		return "produce/scDisinfect/scDisinfect";
	}
	
	@ResponseBody
	@GetMapping("/list")
//	@RequiresPermissions("produce:scDisinfect:scDisinfect")
	public Result<Page<ScDisinfectVO>> list(Integer pageNumber, Integer pageSize, ScDisinfectDO scDisinfectDTO){
		// 查询列表数据
        Page<ScDisinfectVO> page = scDisinfectService.getScDisinfectVOPage(pageNumber,pageSize,scDisinfectDTO);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
//	@RequiresPermissions("produce:scDisinfect:add")
	String add(){
	    return "produce/scDisinfect/add";
	}

	@GetMapping("/add/{produceTaskId}")
	String add(@PathVariable("produceTaskId")Integer produceTaskId,Model model){
		model.addAttribute("produceTaskId",produceTaskId);
		return "produce/scDisinfect/add";
	}

	@GetMapping("/edit/{disinfectId}")
//	@RequiresPermissions("produce:scDisinfect:edit")
	String edit(@PathVariable("disinfectId") Integer disinfectId,Model model){
		ScDisinfectDO scDisinfect = scDisinfectService.selectById(disinfectId);
		model.addAttribute("scDisinfect", scDisinfect);
	    return "produce/scDisinfect/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
//	@RequiresPermissions("produce:scDisinfect:add")
	public Result<String> save( ScDisinfectDO scDisinfect){
		scDisinfect.setCreateBy(getUserId());
		scDisinfect.setCreateDate(Calendar.getInstance().getTime());
		if(scDisinfectService.addScDisinfectDO(scDisinfect)){
			return Result.ok();
		}
		return Result.fail();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
//	@RequiresPermissions("produce:scDisinfect:edit")
	public Result<String>  update( ScDisinfectDO scDisinfect){
		scDisinfectService.updateById(scDisinfect);
		return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
//	@RequiresPermissions("produce:scDisinfect:remove")
	public Result<String>  remove( Integer disinfectId){
		if(scDisinfectService.deleteScDisinfectDO(disinfectId)){
            return Result.ok();
		}
		return Result.fail();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
//	@RequiresPermissions("produce:scDisinfect:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Integer[] disinfectIds){
		for (int i = 0; i < disinfectIds.length; i++) {
			scDisinfectService.deleteScDisinfectDO(disinfectIds[i]);
		}
		return Result.ok();
	}
	
}
